﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using UcAsp.Models;
namespace UcAsp.Controllers
{
    public class AnswerController : Controller
    {
        //
        // GET: /Answer/
         private UcAspNetEntities entities = new UcAspNetEntities();
        public ActionResult Index()
         {
             var query = (from c in entities.Articless
                          where c.CategorieID == 17 && c.IsRelease == true
                          orderby c.Rate descending
                          select c);
             int pagesize = 10;
             int pageindex = 0;
             if (Request.QueryString["page"] != null)
             {
                 pageindex = int.Parse(Request.QueryString["page"].ToString()) - 1;
             }
             ViewData["PageIndex"] = pageindex + 1;
             ViewData["PageCount"] = (query.Count() + 9) / 10;
             List<Articles> list = new List<Articles>();
             list = query.Skip(pageindex * pagesize).ToList<Articles>().Take(pagesize).ToList();
             return View(list);
        }
        public ActionResult AnswerMessage(int id)
        {
            Articles a = entities.Articless.FirstOrDefault(o => o.ID == id);
            if (a == null)
            {
                a = new Articles();
            }
                return View(a);
        }
    }
}
